package com.guoranhao.tool.enums;


/**
 * 图片来源枚举
 */

public enum FileUploadSourceEnum {

    SOURCE_GUORANHAO_SHOP(1, "果然好商城", "guoranhaoshop"),
    ;

    /**
     * 来源
     */
    private int source;
    /**
     * 备注
     */
    private String remark;
    /**
     * 上传文件存储的文件夹
     */
    private String bucketName;

    FileUploadSourceEnum(int source, String remark, String bucketName) {
        this.source = source;
        this.remark = remark;
        this.bucketName = bucketName;
    }

    public int getSource() {
        return source;
    }

    public void setSource(int source) {
        this.source = source;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    /**
     * 校验来源是否有效
     *
     * @param source
     * @return
     */
    public static boolean checkSource(int source) {
        FileUploadSourceEnum[] elements = FileUploadSourceEnum.values();
        for (int i = 0; i < elements.length; i++) {
            if (elements[i].getSource() == source) {
                return true;
            }
        }
        return false;
    }

    /**
     * 通过来源获取文件夹名字
     *
     * @param source
     * @return
     */
    public static String getFolderNameBySource(int source) {
        if (source < 1) {
            return "";
        }
        FileUploadSourceEnum[] elements = FileUploadSourceEnum.values();
        for (int i = 0; i < elements.length; i++) {
            int src = elements[i].getSource();
            if (src == source) {
                return elements[i].getBucketName();
            }
        }
        return "";
    }

    /**
     * 通过环境获取url前缀
     *
     * @param env
     * @return
     */
    public static String getEnvBySource(int env) {
        if (env == 1) {
            return "https://cloud-young-saas.oss-cn-beijing.aliyuncs.com/";
        }
        return "https://cloud-young-saas-test.oss-cn-beijing.aliyuncs.com/";
    }
}
